//
//  BaseApi.m
//  danpin
//
//  Created by chuangjia on 8/12/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "BaseApi.h"
#define BASEURL @"http://api.danpin.com"
@implementation BaseApi

- (id)init {
    self = [super init];
    if (self) {
        
    }
    return self;
}
-(void)dealloc
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}
+(NSString*)publicParams
{
    NSString *params =@"&os=%@&appVer=%@&osVer=%@&partner=%@&uuid=%@&guest_id=%@&guest_name=%@&token=%@";
    NSString *strul =[NSString stringWithFormat:params,
                      [ZShare sharedInstance].systemModel,
                      [ZShare sharedInstance].appVer,
                      [ZShare sharedInstance].osVer,
                      @"appstore",
                      [ZShare sharedInstance].getUUID,
                      [[ZShare sharedInstance] getUserId],
                      [[ZShare sharedInstance] getUserNickname],
                      [[ZShare sharedInstance] pushToken]];
    
    return strul;
}
+(void)cancel
{
    [[ZApi SharedZApi] cancel];
}
+(void)requestWithUrl:(NSString*)strUrl params:(NSDictionary*)params allowFetchCache:(BOOL)allowFetchCache success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *sstrul =[NSString stringWithFormat:@"%@%@%@",BASEURL,strUrl,[self publicParams]];
    DLog(@"%@",sstrul);
    [[ZApi SharedZApi] requestWithURL:sstrul paras:params type:ZHttpResponseType_Json allowFetchCache:allowFetchCache success:^(AFHTTPRequestOperation *operation, id resultObject) {
        success(operation,resultObject);
    } failure:^(NSError *requestErr) {
        failure(requestErr);
    }];
}
@end
